package pingan.com.imandtwo.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.zaaach.toprightmenu.MenuItem;
import com.zaaach.toprightmenu.TopRightMenu;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import pingan.com.imandtwo.R;
import pingan.com.imandtwo.activity.ChatActivity;
import pingan.com.imandtwo.activity.SeachActivity;


/**
 * Created by xsj on 2018/2/1.
 * 这是科技圈
 */

public class ScienceFragment extends Fragment {

    Unbinder unbinder;
    @BindView(R.id.tiao)
    LinearLayout tiao;
    @BindView(R.id.tiao2)
    LinearLayout tiao2;
    @BindView(R.id.sc_name)
    TextView scName;
    @BindView(R.id.sc_name2)
    TextView scName2;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.sciencefragment, container, false);
        final ImageView imagmore = view.findViewById(R.id.more);
        EditText edseach = view.findViewById(R.id.seach);
        edseach.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SeachActivity.class);
                startActivity(intent);
            }
        });
        imagmore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                TopRightMenu mTopRightMenu = new TopRightMenu(getActivity());
                List<MenuItem> menuItems = new ArrayList<>();
                menuItems.add(new MenuItem(R.mipmap.multichat, "发起" +
                        "聊天"));
                menuItems.add(new MenuItem(R.mipmap.addmember, "加好友"));
                menuItems.add(new MenuItem(R.mipmap.qr_scan, "扫一扫"));
                mTopRightMenu
                        .setHeight(360)     //默认高度480
                        .setWidth(320)      //默认宽度wrap_content
                        .showIcon(true)
                        .dimBackground(true)
                        .needAnimationStyle(true)
                        .setAnimationStyle(R.style.TRM_ANIM_STYLE)  //默认为R.style.TRM_ANIM_STYLE
                        .addMenuList(menuItems)
                        .setOnMenuItemClickListener(new TopRightMenu.OnMenuItemClickListener() {
                            @Override
                            public void onMenuItemClick(int position) {
                                Toast.makeText(getActivity(), "点击菜单:" + position, Toast.LENGTH_SHORT).show();
                            }
                        })
                        .showAsDropDown(imagmore, -225, 0);
//                        .showAsDropDown(moreBtn);
                //woaiiaiadddd
            }
        });

        unbinder = ButterKnife.bind(this, view);
        return view;

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.tiao, R.id.tiao2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tiao:
                String s = scName.getText().toString();
                Intent intent = new Intent(getActivity(), ChatActivity.class);
                intent.putExtra("name", "17600545767");
                intent.putExtra("tex", s);
                startActivity(intent);
                break;
            case R.id.tiao2:
                String s1 = scName2.getText().toString();
                Intent intent1 = new Intent(getActivity(), ChatActivity.class);
                intent1.putExtra("name", "17600545767");
                intent1.putExtra("tex", s1);
                startActivity(intent1);
                break;
        }
    }

//    @OnClick(R.id.tiao)
//    public void onClick() {
//
//        startActivity(new Intent(getActivity(), ChatActivity.class));
//
//    }
}
